package com.erli.exchange.core.beans.page;

import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@ApiModel("分页对象")
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult<T> {

	@ApiModelProperty(value = "当前页号")
	private int pageNum;

	@ApiModelProperty(value = "每页的数量")
	private int pageSize;

	@ApiModelProperty(value = "总记录数")
	private long total;

	@ApiModelProperty(value = "总页数")
	private int pages;

	@ApiModelProperty(value = "结果集")
	private List<T> list;

	public static int getPages(long total, int pageSize) {
		if (total == 0 || pageSize == 0) {
			return 0;
		}
		return (int) (total % pageSize == 0 ? (total / pageSize) : (total / pageSize + 1));
	}

	public int getPages() {
		return getPages(this.total, this.pageSize);
	}
}
